package com.example.mybaitsplusdemo.controller;

import com.example.mybaitsplusdemo.entity.User;
import com.example.mybaitsplusdemo.mapper.UserMapper;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "测试模块",tags = "测试模块")
@RestController
@RequestMapping("/users")
public class controller {

    @Autowired
    private UserMapper userMapper;


    @GetMapping
    @ApiOperation(value = "查询所有用户")
    public List<User> listAll() {
        List<User> todos = userMapper.selectList(null);
        return todos;

    }



    @DeleteMapping
    @ApiOperation(value = "删除用户")
    @ApiImplicitParam(name = "id",value = "用户Id",dataType = "long",required = true,defaultValue = "0")
    public int delete(long id){

        return userMapper.deleteById(id);

    }

    @PostMapping
    @ApiOperation(value = "添加用户")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name ="name",value = "用户名",dataType = "String",required = true),
                    @ApiImplicitParam(name = "age",value = "用户年龄",dataType = "int",required = true)
            }
    )
    public int insert(User user){
        return userMapper.insert(user);
    }

    @PutMapping
    @ApiOperation(value = "修改用户")
    public int update(User user){
        return userMapper.updateById(user);
    }




}
